package interfaces.menu.joinGame;

import logic.common.game.GameMode;
import main.GameCycle;
import fileHandling.language.LanguageLoader;
import fileHandling.language.interfaces.MenuText;
import fileHandling.language.interfaces.NewGameText;
import fileHandling.language.options.Filters;
import interfaces.GUISource;
import interfaces.ImageUpdater;
import interfaces.menu.joinGame.gamesTable.GamesTableWidget;
import interfaces.superWidgets.KeyValueContent;
import interfaces.superWidgets.StaticContent;

public class GameDetailsContent extends StaticContent {
	
	private ImageUpdater preview;
	private KeyValueContent infoContent;
	
	private int border;
	
	public GameDetailsContent(int width, int height) {
		super(width, height);
		
		border = height / 16;
		
		createPreview();
		createInfoContent();
	}
	
	private void createPreview() {
		int height = getHeight() / 3 * 2;
		int width = height / 3 * 4;
		int x = 0;
		int y = getHeight() - height;
		preview = new ImageUpdater(x, y, width, height);
		addWidget(preview);
	}
	
	private void createInfoContent() {
		int x = preview.getWidth() + preview.getX() + border;
		infoContent = new KeyValueContent(width - x - border, height - (2 * border), GUISource.middleFont, true);
		infoContent.setXY(x, border);
		addWidget(infoContent);
	}
	
	public void setGame(GamesTableWidget game) {
		preview.setImage("data/maps/" + game.getCurrentMap() + "/preview.png");
		infoContent.clear();
		
		GameCycle gameCycle = game.getGameCycle();
		
		String left = LanguageLoader.get(NewGameText.Balanced_Teams);
		String right = LanguageLoader.get(MenuText.getYesNo(gameCycle.hasBalancedTeams()));
		infoContent.addLine(left, right);
		
		left = LanguageLoader.get(NewGameText.Enable_Bots);
		right = LanguageLoader.get(MenuText.getYesNo(gameCycle.botsEnabled()));
		infoContent.addLine(left, right);
		
		left = LanguageLoader.get(NewGameText.Respawn_Time);
		right = gameCycle.getRespawnTime() + "";
		infoContent.addLine(left, right);
		
		left = LanguageLoader.get(Filters.Friendly_Fire);
		right = LanguageLoader.get(MenuText.getYesNo(gameCycle.hasFriendlyFire()));
		infoContent.addLine(left, right);
		
		GameMode mode = gameCycle.getGameMode();
		if(mode == GameMode.Conquest) {
			left = LanguageLoader.get(NewGameText.Tickets);
			right = gameCycle.getTickets() + "";
			infoContent.addLine(left, right);
		} else if(mode == GameMode.TeamDeathmatch) {
			left = LanguageLoader.get(NewGameText.Score_Limit);
			right = gameCycle.getScoreLimit() + "";
			infoContent.addLine(left, right);
		}
		
		layout();
	}
	
	public void clear() {
		preview.getAppearance().removeAll();
		infoContent.clear();
		layout();
	}
	
	public int getPreviewY() { return preview.getY(); }
	
	public int getPreviewWidth() { return preview.getWidth(); }
}